<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var characterTesterDataGrid;
    $(function () {
        characterTesterDataGrid = $('#characterTesterDataGrid').datagrid({
            url: '${path}/characterTester/dataGrid',
            striped: true,
            rownumbers: true,
            pagination: true,
            singleSelect: true,
            idField: 'id',
            sortName: 'id',
            sortOrder: 'asc',
            pageSize: 20,
            pageList: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
            columns: [[{
                width: '60',
                title: '编号',
                field: 'id',
                sortable: true
            }
                , {
                    width: '60',
                    title: '姓名',
                    field: 'name',
                    sortable: true
                }
                ,
                {
                    width: '100',
                    title: '手机号',
                    field: 'phone',
                    sortable: true
                }

                ,
                {
                    width: '140',
                    title: '测试时间',
                    field: 'createTime',
                    sortable: true
                },

                {
                    width: '150',
                    title: '红色性格',
                    field: 'redCount',
                },     {
                    width: '150',
                    title: '蓝色性格',
                    field: 'blueCount',
                },    {
                    width: '150',
                    title: '黄色性格',
                    field: 'yellowCount',
                },    {
                    width: '150',
                    title: '绿色性格',
                    field: 'greenCount',
                },{
                    field: 'action',
                    title: '操作',
                    width: 200,
                    formatter: function (value, row, index) {
                        var str = '';
                        <shiro:hasPermission name="/characterTester/edit">
                        str += $.formatString('<a href="javascript:void(0)" class="characterTester-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="characterTesterEditFun(\'{0}\');" >编辑</a>', row.id);
                        </shiro:hasPermission>
                        <shiro:hasPermission name="/characterTester/delete">
                        str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                        str += $.formatString('<a href="javascript:void(0)" class="characterTester-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="characterTesterDeleteFun(\'{0}\');" >删除</a>', row.id);
                        </shiro:hasPermission>
                        return str;
                    }
                }]],
            onLoadSuccess: function (data) {
                $('.characterTester-easyui-linkbutton-edit').linkbutton({text: '编辑'});
                $('.characterTester-easyui-linkbutton-del').linkbutton({text: '删除'});
            },
            toolbar: '#characterTesterToolbar'
        });
    });

    /**
     * 添加框
     * @param url
     */
    function characterTesterAddFun() {
        parent.$.modalDialog({
            title: '添加',
            width: 700,
            height: 600,
            href: '${path}/characterTester/addPage',
            buttons: [{
                text: '确定',
                handler: function () {
                    parent.$.modalDialog.openner_dataGrid = characterTesterDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#characterTesterAddForm');
                    f.submit();
                }
            }]
        });
    }


    /**
     * 编辑
     */
    function characterTesterEditFun(id) {
        if (id == undefined) {
            var rows = characterTesterDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            characterTesterDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title: '编辑',
            width: 700,
            height: 600,
            href: '${path}/characterTester/editPage?id=' + id,
            buttons: [{
                text: '确定',
                handler: function () {
                    parent.$.modalDialog.openner_dataGrid = characterTesterDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#characterTesterEditForm');
                    f.submit();
                }
            }]
        });
    }


    /**
     * 删除
     */
    function characterTesterDeleteFun(id) {
        if (id == undefined) {//点击右键菜单才会触发这个
            var rows = characterTesterDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {//点击操作里面的删除图标会触发这个
            characterTesterDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除当前角色？', function (b) {
            if (b) {
                progressLoad();
                $.post('${path}/characterTester/delete', {
                    id: id
                }, function (result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        characterTesterDataGrid.datagrid('reload');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }


    /**
     * 清除
     */
    function characterTesterCleanFun() {
        $('#characterTesterSearchForm input').val('');
        characterTesterDataGrid.datagrid('load', {});
    }

    /**
     * 搜索
     */
    function characterTesterSearchFun() {
        characterTesterDataGrid.datagrid('load', $.serializeObject($('#characterTesterSearchForm')));
    }
</script>

<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'north',border:false" style="height: 30px; overflow: hidden;background-color: #fff">
        <form id="characterTesterSearchForm">
            <table>
                <tr>
                    <th>名称:</th>
                    <td><input name="name" placeholder="搜索条件"/></td>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton"
                           data-options="iconCls:'fi-magnifying-glass',plain:true"
                           onclick="characterTesterSearchFun();">查询</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton"
                           data-options="iconCls:'fi-x-circle',plain:true" onclick="characterTesterCleanFun();">清空</a>
                    </td>
                </tr>
            </table>
        </form>
    </div>

    <div data-options="region:'center',border:false">
        <table id="characterTesterDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="characterTesterToolbar" style="display: none;">
    <shiro:hasPermission name="/characterTester/add">
        <a onclick="characterTesterAddFun();" href="javascript:void(0);" class="easyui-linkbutton"
           data-options="plain:true,iconCls:'fi-page-add'">添加</a>
    </shiro:hasPermission>
</div>
